package com.luhuiguo.contacts.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.RootPanel;
import com.luhuiguo.contacts.client.gin.Injector;
import com.luhuiguo.contacts.client.presenter.ContactsPresenter;

/**
 * 
 * @author LuHuiguo
 * @version $Id: Contacts.java 23 2010-03-13 07:58:04Z luhuiguo@gmail.com $
 */
public class Contacts implements EntryPoint {

    private final Injector injector = GWT.create(Injector.class);

    private final AppConstants constants = GWT.create(AppConstants.class);

    // private final AppMessages messages = GWT.create(AppMessages.class);

    @Override
    public void onModuleLoad() {

        prepareLoadingIndicator();

        GWT.<AppResources> create(AppResources.class).css().ensureInjected();

        ContactsPresenter contactsPresenter = injector.getContactsPresenter();

        contactsPresenter.bind();

        RootPanel rootPanel = RootPanel.get("contact");
        if (rootPanel == null) {
            rootPanel = RootPanel.get();
        }
        rootPanel.add(contactsPresenter.getDisplay().asWidget());

    }

    private void prepareLoadingIndicator() {
        LoadingStatus status = new LoadingStatus(constants.loading());
        AsyncCallbackWithStatus.setLoadingIndicator(status);
    }

}
